# K9s plugins: https://github.com/derailed/k9s/tree/master/plugins
# See https://k9scli.io/topics/plugins/
plugins:
  log-less:
    shortCut: Shift-L
    description: "logs|less"
    scopes:
      - po
    command: bash
    background: false
    args:
      - -c
      - '"$@" | less'
      - dummy-arg
      - kubectl
      - logs
      - $NAME
      - -n
      - $NAMESPACE
      - --context
      - $CONTEXT
      - --kubeconfig
      - $KUBECONFIG

  log-less-container:
    shortCut: Shift-L
    description: "logs|less"
    scopes:
      - containers
    command: bash
    background: false
    args:
      - -c
      - '"$@" | less'
      - dummy-arg
      - kubectl
      - logs
      - -c
      - $NAME
      - $POD
      - -n
      - $NAMESPACE
      - --context
      - $CONTEXT
      - --kubeconfig
      - $KUBECONFIG

  #get all resources in a namespace using the krew get-all plugin
  get-all:
    shortCut: g
    confirm: false
    description: get-all
    scopes:
      - all
    command: sh
    background: false
    args:
      - -c
      - "kubectl get-all -n $NAMESPACE | less"

  # View user-supplied values when the helm chart was created
  helm-values:
    shortCut: v
    confirm: false
    description: Values
    scopes:
      - helm
    command: sh
    background: false
    args:
      - -c
      - "helm get values $COL-NAME -n $NAMESPACE --kube-context $CONTEXT | less"

  # View default helm chart values
  helm-default-values:
    shortCut: Shift-V
    confirm: false
    description: Chart Default Values
    scopes:
      - helm
    command: sh
    background: false
    args:
      - -c
      - >-
        revision=$(helm history -n $NAMESPACE --kube-context $CONTEXT $COL-NAME | grep deployed | cut -d$'\t' -f1 | tr -d ' \t');
        kubectl
        get secrets
        --context $CONTEXT
        -n $NAMESPACE
        sh.helm.release.v1.$COL-NAME.v$revision -o yaml
        | yq e '.data.release' -
        | base64 -d
        | base64 -d
        | gunzip
        | jq -r '.chart.values'
        | yq -P
        | less -K

  # Issues a helm delete --purge for the resource associated with the selected pod
  helm-purge:
    shortCut: Ctrl-P
    description: Helm Purge
    scopes:
      - po
    command: kubectl
    background: true
    args:
      - purge
      - $NAMESPACE
      - $NAME

  # Sends logs over to jq for processing. This leverages kubectl plugin kubectl-jq.
  jqlogs:
    shortCut: Ctrl-J
    confirm: false
    description: "Logs (jq)"
    scopes:
      - po
    command: kubectl
    background: false
    args:
      - jq
      - $NAME
      - $NAMESPACE
      - $CONTEXT

  # Inspect container images
  dive:
    shortCut: Ctrl-D
    confirm: false
    description: "Dive image"
    scopes:
      - containers
    command: dive
    background: false
    args:
      - $COL-IMAGE

  #--- Create debug container for selected pod in current namespace
  # See https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/#ephemeral-container
  debug:
    shortCut: Shift-D
    description: Add debug container
    scopes:
      - containers
    command: bash
    background: false
    confirm: true
    args:
      - -c
      - "kubectl debug -it -n=$NAMESPACE $POD --target=$NAME --image=nicolaka/netshoot:v0.12 --share-processes -- zsh"
